package sdk3
{
	/** IMPORTS **/
	
	
	import flash.events.Event;
	
	import mx.controls.DateField;
	
	import sdk3.components.TextInputExtended.TIE;

	public class c_DATE
	{
	/*******************************************************************************
	* Software: c_DATE												
	* Version:  v1.4
	* Date:     15.01.2009_TIME_12:06:49     
	* Author:    
	* 	  * LICENSE:  GNU General Public License (http://www.gnu.org/licenses/gpl.html) 	 *  	 * English: 		This program is free software; 		you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; 		either version 3 of the License, or (at your option) any later version.   		This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 		without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 		See the GNU General Public License for more details. 		You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.   		 * Excerpt English: 		 * Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), 		 * that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things   		Auf Deutsch: 		Dieses Programm ist freie Software. Sie können es unter den Bedingungen der GNU General Public License, wie von der Free Software Foundation veröffentlicht, 		weitergeben und/oder modifizieren, entweder gemäß Version 3 der Lizenz oder (nach Ihrer Option) jeder späteren Version. 		Die Veröffentlichung dieses Programms erfolgt in der Hoffnung, daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, 		sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. 		Details finden Sie in der GNU General Public License. 		Sie sollten ein Exemplar der GNU General Public License zusammen mit diesem Programm erhalten haben. 		Falls nicht, siehe <http://www.gnu.org/licenses/>.   		 * Auszug Deutsch: 		 * Wenn wir von freier Software sprechen, so beziehen wir uns auf Freiheit, nicht auf den Preis. 		 * Unsere Allgemeinen Öffentlichen Lizenzen sind darauf angelegt, sicherzustellen, daß Sie die Freiheit haben, 		 * Kopien freier Software zu verbreiten (und dafür etwas zu berechnen, wenn Sie möchten), die Möglichkeit, 		 * daß Sie die Software als Quelltext erhalten oder den Quelltext auf Wunsch bekommen, daß Sie die Software 		 * ändern oder Teile davon in neuen freien Programmen verwenden dürfen und daß Sie wissen, daß Sie dies alles tun dürfen.   GNU General Public License (http://www.gnu.org/licenses/gpl.html) 	 *  	 * English: 		This program is free software; 		you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; 		either version 3 of the License, or (at your option) any later version.   		This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 		without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 		See the GNU General Public License for more details. 		You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.   		 * Excerpt English: 		 * Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), 		 * that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things   		Auf Deutsch: 		Dieses Programm ist freie Software. Sie können es unter den Bedingungen der GNU General Public License, wie von der Free Software Foundation veröffentlicht, 		weitergeben und/oder modifizieren, entweder gemäß Version 3 der Lizenz oder (nach Ihrer Option) jeder späteren Version. 		Die Veröffentlichung dieses Programms erfolgt in der Hoffnung, daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, 		sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. 		Details finden Sie in der GNU General Public License. 		Sie sollten ein Exemplar der GNU General Public License zusammen mit diesem Programm erhalten haben. 		Falls nicht, siehe <http://www.gnu.org/licenses/>.   		 * Auszug Deutsch: 		 * Wenn wir von freier Software sprechen, so beziehen wir uns auf Freiheit, nicht auf den Preis. 		 * Unsere Allgemeinen Öffentlichen Lizenzen sind darauf angelegt, sicherzustellen, daß Sie die Freiheit haben, 		 * Kopien freier Software zu verbreiten (und dafür etwas zu berechnen, wenn Sie möchten), die Möglichkeit, 		 * daß Sie die Software als Quelltext erhalten oder den Quelltext auf Wunsch bekommen, daß Sie die Software 		 * ändern oder Teile davon in neuen freien Programmen verwenden dürfen und daß Sie wissen, daß Sie dies alles tun dürfen. 
	 * 
	* Purpose:
	 * WHAT?
		 * beinhaltet funktionen welche sich mit dem rechnen von datums-angaben beschäftigen.
	 * TODO:
	 * KNOWN BUGS: 
	 * CHANGELOG:
		 * 11.01.2009_TIME_08:55:59
		 * verbesserung an aktuelles_Datum_as_String
	 * 
	 * HOWTO/USAGE/EXAMPLES:
	 * The Date class lets you retrieve date and time values relative to universal time (Greenwich mean time,
	 * now called universal time or UTC) or relative to local time, which is determined by the local time zone
	 * setting on the operating system that is running Flash Player.
	 * 
	 **/

		/**
		 * ABOUT DATE:
		 * 
		 * The Date class lets you retrieve date and time values relative to universal time (Greenwich mean time,
		 * now called universal time or UTC) or relative to local time, which is determined by the local time zone
		 * setting on the operating system that is running Flash Player.
		 **/

		private static var instance:c_DATE = null;
		
		public static function singleton():c_DATE
		{
			if (instance == null) 
			{
				instance = new c_DATE();
			}
			return instance;
		}
		
		/** ======================== INST **/
		var c_VALIDATORS_inst:c_VALIDATORS = new c_VALIDATORS();
		
		/** ======================== VARS **/
		
		var STRING_RESULT:String = '';
		var counter:int = 0;
		var counter1:int = 0;
		var counter2:int = 0;
		var LENGTH:int = 0;
		var LENGTH1:int = 0;
		var LENGTH2:int = 0;
		// zum rechnen mit Daten/Datumsangaben
		 
		public function c_DATE()
		{
		}
	
		// ========= Datum +/- X-Tage
		
		public function calc_date_plus_days_return_date(DATE_input:Date,NUMBER_Days:Number):Date
		{
			if(NUMBER_Days == 0)
			{
				return DATE_input;
			}
			
			var DATE_ResultDate:Date = new Date(DATE_input.getTime() + Days2Milliseconds( NUMBER_Days ) );
			
			trace( DATE_ResultDate );
			
			return DATE_ResultDate;
		}
	
		public function calc_date_plus_days_return_string(STRING_Datum:String,NUMBER_Days:Number):String
		{
			if(NUMBER_Days == 0)
			{
				return STRING_Datum;
			}
	
			var STRING_ResultDate:String = '';
			
			if(STRING_Datum != null && NUMBER_Days != undefined)
			{
				var DATE_Datum:Date = string_to_date(STRING_Datum,'DD.MM.YYYY');
				
				try
				{
					var DATE_ResultDate:Date = new Date(DATE_Datum.getTime() + Days2Milliseconds( NUMBER_Days ) );
				}
				catch(e:Error)
				{
					// auf solche daten kommt der ned klar :) STRING_Datum = "28.08.11151"	
				}
				
				STRING_ResultDate = date_to_string(DATE_ResultDate);
			}
			
			return STRING_ResultDate;
		}
		
		// ========= KONVERTIEREN

		/** goes through an array that contains objects -> object[KEY] -> value-int number since 1.1.1970
		 * and converts it into human readable format **/
		public function date_to_string_in_array(ARRAY:Array,KEY:String):Array
		{
			var c_OBJECT_inst:c_OBJECT = new c_OBJECT();
			var RESULT:Array = c_OBJECT_inst.copy(ARRAY);
			for(var counter:int = 0;!(counter == RESULT.length);counter++)
			{
				RESULT[counter][KEY] = date_to_string(new Date(RESULT[counter][KEY]));
			}
			
			return RESULT;
		}
		
		public function date_to_string(DATE_date:Date,FORMAT:String = 'DD.MM.YYYY'):String
		{
			var STRING_result:String = '';
			// Just BTW: Flex assigns 0 to January, 1 to February, 2 to March, ...
			if(DATE_date != null)
			{
				if(FORMAT == 'DD.MM.YYYY')
				{
					// trace(DATE_date.toDateString()); // Fri Sep 12 2008
					
					// trace('UTC:'+DATE_date.dateUTC.toString()+'.'+(DATE_date.monthUTC+1).toString()+'.'+DATE_date.fullYear); // 12.9.2008
					
					/** I PREFER THIS OVER UTC, because when using
					 * 	var DATUM_result:Date = c_DATE_inst.string_to_date(STRING_Datum,STRING_DateFormat);
					 the UTC values are not set correctly. **/
			
					// trace('   :'+DATE_date.date.toString()+'.'+(DATE_date.month+1).toString()+'.'+DATE_date.fullYear); // 12.9.2008
					
					var STRING_month:String = (DATE_date.month+1).toString();
					
					if(STRING_month.length == 1) // ein ziffriger monat hänge ne null hin
					{
						STRING_month = '0'+STRING_month
					}
					var STRING_day:String = DATE_date.date.toString();
					
					if(STRING_day.length == 1) // ein ziffriger monat hänge ne null hin
					{
						STRING_day = '0'+STRING_day
					}
					
					STRING_result = STRING_day+'.'+STRING_month+'.'+DATE_date.fullYear;
					// trace(STRING_result); // 12.09.2008
				}
				
				if(FORMAT == 'YYYY-MM-DD')
				{
					var STRING_month:String = (DATE_date.month+1).toString();
					if(STRING_month.length == 1) // ein ziffriger monat hänge ne null hin
					{
						STRING_month = '0'+STRING_month
					}
					var STRING_day:String = DATE_date.date.toString();
					if(STRING_day.length == 1) // ein ziffriger monat hänge ne null hin
					{
						STRING_day = '0'+STRING_day
					}
					STRING_result = DATE_date.fullYear+'-'+STRING_month+'-'+STRING_day;
					// trace(STRING_result); // 12.09.2008
				}
			}
			
			return STRING_result;
		}
	
	    /**
	     *  Parses a String object that contains a date, and returns a Date
	     *  object corresponding to the String.
	     *  The <code>inputFormat</code> argument contains the pattern
	     *  in which the <code>valueString</code> String is formatted.
	     *  It can contain <code>"M"</code>,<code>"D"</code>,<code>"Y"</code>,
	     *  and delimiter and punctuation characters.
	     *
	     *  The function does not check for the validity of the Date object.
	     *  If the value of the date, month, or year is NaN, this method returns null.
	     *
	     *  @param valueString Date value to format.
	     *
	     *  @param inputFormat String defining the date format.
	     *
	     *  @return The formatted date as a Date object.
	     *
	     *  @example
	     *  <pre>var dob:Date = c_DATE_inst.string_to_date("06/30/2005", "MM/DD/YYYY");</pre>
	     * 
	     */
	//    public static function stringToDate(valueString:String, inputFormat:String):Date
	
		/** i guess this flex build-in function IS NOT WORKING PROPERLY
		 * giving this: 10/7/11
		 * 
		 * with FORMAT == DD/MM/YYYY
		 * 
		 * would result in:
		 * 
		 * DATE = <Sun Jul 10 00:00:00 GMT+0200 2011> (@8304641)	
			date = 10 [0xa]	
			dateUTC = 9 <- WRONG! SHOULD BE 10	
			day = 0	
			dayUTC = 6	<- WRONG!
			fullYear = 2011 [0x7db]	
			fullYearUTC = 2011 [0x7db]	
			hours = 0	
			hoursUTC = 22 [0x16]	<- WTF? IT WAS NO TIME GIVEN! i guess it's because of the timezoneOffset
			milliseconds = 0	
			millisecondsUTC = 0	
			minutes = 0	
			minutesUTC = 0	
			month = 6	<- WRONG SHOULD BE 7
			monthUTC = 6	
			seconds = 0	
			secondsUTC = 0	
			time = 1310248800000 [0x13110ea0f00]	
			timezoneOffset = -120 [0xffffff88]	
		 * **/
	 	public function string_to_date(DATE_STRING:String,FORMAT:String = 'DD.MM.YYYY'):Date // FORMAT = 'DD.MM.YYYY'
	 	{
	 		var DATE:Date = null;
	 		if(DATE_STRING != null)
	 		{
				DATE = DateField.stringToDate(DATE_STRING,FORMAT);
				// DATE = new Date(DATE.getTime() - timeZone2ms(DATE));
				// DATE.hours = 0;
				DATE.hours = 0;
				// DATE.minutes = 0;
				DATE.minutes = 0;
				// DATE.seconds = 0;
				DATE.seconds = 0;
				/** setz dateUTC nicht korrekt **/
	 		}
			
			return DATE;
	 	}
		
		/** converts timeZone2 milli seconds **/
		public function timeZone2ms(DATE:Date):Number
		{
			return (60 * 1000 * DATE.timezoneOffset);
		}
	
		/** converts a date directly to MySQL-String **/
		public function dateToMySQLString(DATE:Date):String
		{
			var RESULT:String = date_string_to_mysql_date(date_to_string(DATE));
			
			return RESULT;
		}
		
		/** ================ UTILITIES ================ **/
		/** konvertiert 12.01.2008 in mysql kompatibles format 2008-01-12  v1.1. **/
		 public function date_string_to_mysql_date(STRING_Datum:String,DELIMITER:String = '-'):String
		 {
		 	if(STRING_Datum != null && STRING_Datum != '')
		 	{
		 		/** 2009-09-21 -> 3 parts **/
		 		if(c_VALIDATORS_inst.validateDate(STRING_Datum))
		 		{
		 			/** start converting **/
			 		var ARRAY:Array = STRING_Datum.split('.');
			 		if(ARRAY.length > 1)
			 		{
						var newDatum:String = ''; // STRING_Datum.replace('.','');
						// newDatum = newDatum.replace('.','');
	
						var dd:String = ARRAY[0]; // split is even faster than = newDatum.substr(0,2);
						var mm:String = ARRAY[1]; // split is even faster than = newDatum.substr(2,2);
						var yy:String = ARRAY[2]; // split is even faster than = newDatum.substr(4,4);
						
						newDatum = yy + DELIMITER + mm + DELIMITER + dd;
				 	}
				 	else
				 	{
				 		trace('date_string_to_mysql_date: kein gültiges sql datum im format DD.MM.YYYY, return nothing');
				 		newDatum = '';
				 	}
		 		}
		 		else
		 		{
		 			/** was probably allready mysql-date format **/
		 			trace('was probably allready mysql-date format do not convert '+STRING_Datum);
		 			newDatum = STRING_Datum;
		 		}
		 	}
		 	else
		 	{
		 		// trace('date_string_to_mysql_date: string war leer.');
		 		newDatum = '';
		 	}
			
			return newDatum;
		 }

		/** konvertiert an array with lot's of dates from 12.01.2008 in mysql kompatibles format 2008-01-12 **/
		 public function ARRAY_date_string_to_mysql_date(ARRAY:Array,DATE_PROPERTIES:Array):Array
		 {
		 	if(ARRAY != null)
		 	{
			 	LENGTH = ARRAY.length;
		 		for(counter = 0;!(counter == LENGTH);counter++)
		 		{
			 		for(counter1 = 0;!(counter1 == DATE_PROPERTIES.length);counter1++)
			 		{
			 			ARRAY[counter][DATE_PROPERTIES[counter1]] = date_string_to_mysql_date(ARRAY[counter][DATE_PROPERTIES[counter1]]);
			 		}
		 		}
		 	}
		 	
		 	return ARRAY;
	 	}


	/** konvertiert 2008-01-12 in mysql kompatibles format 12.01.2008
	 * prüft vorher ob es sich um ein mysql kompatibles format handelt, falls nicht, kommt das original datums-format zurück. **/
	 public function mysql_date_to_date_string(STRING_Datum:String):String
	 {
	 	if(STRING_Datum != null && STRING_Datum != '')
	 	{
			var yy:String = '';
			var mm:String = '';
			var dd:String = '';
			
			var valid_sql_date:Boolean = false;
	
		 	// detect if string is containing '-' -> if yes is probably valid sql string
		 	var ARRAY:Array = STRING_Datum.split('-');
		 	if(ARRAY.length > 1)
		 	{
		 		// 2009-09-01
		 		yy = ARRAY[0];
		 		mm = ARRAY[1];
		 		dd = ARRAY[2];
		 		if(yy.length == 4 && mm.length == 2 && dd.length == 2)
		 		{
			 		if(c_VALIDATORS_inst.validateInt(yy) && c_VALIDATORS_inst.validateInt(mm) && c_VALIDATORS_inst.validateInt(dd))
			 		{
			 			valid_sql_date = true;
			 		}
			 		else
			 		{
			 			valid_sql_date = false;
			 		}
		 		}
		 		else
		 		{
		 			valid_sql_date = false;
		 		}
		 	}
		 	else
		 	{
		 		valid_sql_date = false;
		 		trace('mysql_date_to_date_string: kein gültiges sql datum im format YYYY-MM-DD, return original string.');
		 	}

			if(valid_sql_date)
			{
	/*			// mit substring, auch möglich. 
				var newDatum:String = STRING_Datum.replace('-','');
				newDatum = newDatum.replace('-','');
			
				var yy:String = newDatum.substr(0,4);
				var mm:String = newDatum.substr(4,2);
				var dd:String = newDatum.substr(6,2);
	 */			
				STRING_Datum = dd + '.' + mm + '.' + yy;
			}
			else
			{
				trace('mysql_date_to_date_string: \"'+STRING_Datum+'\" ist kein gültiges MySQL-datums format.');
			}
		 }
		 else
		 {
			// trace('mysql_date_to_date_string: string war leer.');
			STRING_Datum = '';
			
		 }
		
		return STRING_Datum;	
	 }

		/** konvertiert 2008-01-12 in mysql kompatibles format 12.01.2008 **/
/* 		 public function mysql_date_to_date_string(STRING_Datum:String):String
		 {
		 	if(STRING_Datum != null)
		 	{
		 		var ARRAY:Array = STRING_Datum.split('-');
		 		if(ARRAY.length > 1)
		 		{
					var newDatum:String = ''; // STRING_Datum.replace('-','');
					// newDatum = newDatum.replace('-','');
				
					var yy:String = ARRAY[0]; // .split is even faster than = newDatum.substr(0,4);
					var mm:String = ARRAY[1]; // .split is even faster than = newDatum.substr(4,2);
					var dd:String = ARRAY[2]; // .split is even faster than = newDatum.substr(6,2);
					
					newDatum = dd + '.' + mm + '.' + yy;
		 		}
		 		else
		 		{
		 			// kein gültiges sql datum im format YYYY-MM-DD, return nothing
		 			newDatum = '';
		 		}
			}
			
			return newDatum;	
		 }
 */		 
		/** konvertiert an array with lot's of dates from 2008-01-12 in mysql kompatibles format 12.01.2008 **/
		 public function ARRAY_mysql_date_to_date_string(ARRAY:Array,DATE_PROPERTY:String):Array
		 {
		 	if(ARRAY != null)
		 	{
			 	LENGTH = ARRAY.length;
		 		for(counter = 0;!(counter == LENGTH);counter++)
		 		{
		 			ARRAY[counter][DATE_PROPERTY] = mysql_date_to_date_string(ARRAY[counter][DATE_PROPERTY]);
		 		}
		 	}
		 	
		 	return ARRAY;
	 	}
		 
		/** konvertiert array with object elements that have multiple mysql-like dates example: 2008-01-12
		 * to 'normal' date strings 12.01.2008 and save them back into the array, then return array.
		 * INPUT
		 * 	ARRAY_LabelFields
		 * 		list of labelFields
		 * 
		 * 	ARRAY_Material
		 * 		the array that contains the elements/objects who's mysql-date-values need to be converted.
		 * 
		 * OUTPUT
		 * 		array with converted date values.
		 * **/
		 public function array_with_mysql_dates_to_array_with_normal_dates(ARRAY_LabelFields:Array,ARRAY_Material:Array):Array
		 {
		 	if(ARRAY_LabelFields != null && ARRAY_Material != null)
		 	{
		 		var INT_ARRAY_Material_length:int = ARRAY_Material.length;
		 		for(var counter:int = 0;!(counter == INT_ARRAY_Material_length);counter++)
		 		{
		 			var OBJECT_OP:Object = ARRAY_Material[counter];
		 			
			 		var INT_ARRAY_LabelFields_length:int = ARRAY_LabelFields.length;
			 		for(var counter1:int = 0;!(counter1 == INT_ARRAY_LabelFields_length);counter1++)
			 		{
			 			OBJECT_OP[ARRAY_LabelFields[counter1]] = mysql_date_to_date_string(OBJECT_OP[ARRAY_LabelFields[counter1]]);
			 		}
		 		}
			}
			
			return ARRAY_Material.slice();
		 }
		 
		 /** macht das gleiche wie autoComplete_Date
		 * nur dass man das problemlos an einen FOCUS_OUT oder CHANGE eventlistener
		 * eines textinputs hängen kann
		 * 
		 * usage:
		 * import sdk3.c_DATE;
		 * var c_DATE_inst:c_DATE = new c_DATE();
		 * focusOut="c_DATE_inst.TIE_autoComplete_Date(event);"
		 * **/
		 public function TIE_autoComplete_Date(event:Event):void
		 {
		 	var TIE_inst:TIE = event['currentTarget'] as TIE;
		 	
		 	if(TIE_inst != null)
		 	{
		 		TIE_inst.text = autoComplete_Date(TIE_inst.text);
		 	}
		 }
		 
		 /**
		 * v1.0
		 * 1. reformatiert ein unvollständig eingegebenes datum mit dem AKTUELLEM (SYSTEM) datum
		 * 2. checkt ob dd > 21 < 0, m > 12 < 0 etc. 
		 * ählich des Flex eingebauten DateValidators, nur dass dieser nicht zuverlässig validiert.
		 * user muss fähig sein Datum in folgenden formaten eingeben zu können
		 * 01.01.2008
		 * 01012008
		 * 0101
		 * 01
		 * '' -> aktuelles datum, aus aktuellem tag + perioden-monat + buchungsjahr.
		 * STRING_Date.replace('.','');
		* @return An array of strings consisting of all substrings in 
		* the string that match the specified <code>pattern</code>.
		 * INPUT
		 * MAX_MM -> der maximale gültige Monat.
		 * MIN_MM -> der minmale gültige Monat.
	 	 **/
		
		 public function autoComplete_Date(STRING_Date:String,MAX_MM:int = 12,MIN_MM:int = 1,MAX_YYYY:int = 9999,MIN_YYYY:int = 0):String
		 {
		 	// 0. validieren ob ein gültiges format forliegt
		 	// 1. punkte entfernen, falls vorhanden
	       	
	       	var STRING_DateResult:String = '';
	       	
	       	// replace funktion wo bis zu 3 punkte herausfiltert
	 		STRING_Date = STRING_Date.replace('.','');
	 		STRING_Date = STRING_Date.replace('.','');
	 		STRING_Date = STRING_Date.replace('.','');
	 		
	 		if(validateInt(STRING_Date) == false)
	 		{
	 			// no valid date
	 			// -> leave old date
	 			// STRING_DateResult = STRING_Date;
	 			// -> delete old date
	 			return '';
	 		}
	
			// Check if valid Int
			function validateInt(InputString:String):Boolean // Checkt ob es sich beim Input um ein gültiges Kontonummern-Format handelt d.h. eine ganz-zahlige Nummer ohne Vorzeichen. If input is a number -> true else -> false
			{
			    const RegExInt:RegExp = /^\d+$/g; // matches only int numbers
			    
			    if (RegExInt.test(InputString)) // test returns true if match, else false //// BE CAREFUL! .test proved to do true, false, true... validation errors.
			    {
			   		return true;
			    }
			    else
			    {
			   		return false;
			    }
			}
	 		
	 		var dd:String = '';
	 		var mm:String = '';
	 		var yyyy:String = '';
	     		
			var datum:Date = new Date(); // aktuelles datum
			
	   		// 2. schaun wie viel man hat
	   		if(STRING_Date.length == 1)
	   		{
	   			// wir ham 1
	   			dd = STRING_Date.substr(0,1); // ab char 0, copy 1 stück
	
			   		// dd max 31 min 1
			   		if(parseInt(dd) > 31)
			   		{
			   			dd = '31';
			   		}
			   		if(parseInt(dd) < 1)
			   		{
			   			dd = '1';
			   		}
	   			
	   			dd = '0'+dd;
	   			mm = (datum.month+1).toString();
	
			   		// mm max 12 min 1
			   		if(parseInt(mm) > 12)
			   		{
			   			mm = '12';
			   		}
			   		if(parseInt(mm) < 1)
			   		{
			   			mm = '1';
			   		}
	   			
	   			if(mm.length == 1)
	   			{
	   				mm = '0'+mm;
	   			}
				yyyy = datum.fullYear.toString();
	   		}
	   		
	   		if(STRING_Date.length == 2)
	   		{
	   			// wir ham 01
	   			dd = STRING_Date.substr(0,2); // ab char 0, copy 2 stück
	
			   		// dd max 31 min 1
			   		if(parseInt(dd) > 31)
			   		{
			   			dd = '31';
			   		}
			   		if(parseInt(dd) < 1)
			   		{
			   			dd = '1';
			   		}
	
	   			mm = (datum.month+1).toString();
	
			   		// mm max 12 min 1
			   		if(parseInt(mm) > 12)
			   		{
			   			mm = '12';
			   		}
			   		if(parseInt(mm) < 1)
			   		{
			   			mm = '1';
			   		}
	
	   			if(mm.length == 1)
	   			{
	   				mm = '0'+mm;
	   			}
				yyyy = datum.fullYear.toString();
	   		}
	   		if(STRING_Date.length == 3)
	   		{
	   			// wir ham 011
	   			dd = STRING_Date.substr(0,2); // ab char 0, copy 2 stück
	
			   		// dd max 31 min 1
			   		if(parseInt(dd) > 31)
			   		{
			   			dd = '31';
			   		}
			   		if(parseInt(dd) < 1)
			   		{
			   			dd = '1';
			   		}
	
	   			mm = STRING_Date.substr(2,1); // ab char 2, copy 2 stück
	
			   		// mm max 12 min 1
			   		if(parseInt(mm) > 12)
			   		{
			   			mm = '12';
			   		}
			   		if(parseInt(mm) < 1)
			   		{
			   			mm = '1';
			   		}
	
	   			if(mm.length == 1)
	   			{
	   				mm = '0'+mm;
	   			}
				yyyy = datum.fullYear.toString();
	   		} 
	   		if(STRING_Date.length == 4)
	   		{
	   			// wir ham 0101
	   			dd = STRING_Date.substr(0,2); // ab char 0, copy 2 stück
	
			   		// dd max 31 min 1
			   		if(parseInt(dd) > 31)
			   		{
			   			dd = '31';
			   		}
			   		if(parseInt(dd) < 1)
			   		{
			   			dd = '1';
			   		}
	
	   			mm = STRING_Date.substr(2,2); // ab char 2, copy 2 stück
	
			   		// mm max 12 min 1
			   		if(parseInt(mm) > 12)
			   		{
			   			mm = '12';
			   		}
			   		if(parseInt(mm) < 1)
			   		{
			   			mm = '1';
			   		}
	
	   			yyyy = datum.fullYear.toString();
	   		} 
	   		if(STRING_Date.length == 6)
	   		{
	   			// wir ham 010108
	   			dd = STRING_Date.substr(0,2); // ab char 0, copy 2 stück
	
			   		// dd max 31 min 1
			   		if(parseInt(dd) > 31)
			   		{
			   			dd = '31';
			   		}
			   		if(parseInt(dd) < 1)
			   		{
			   			dd = '1';
			   		}
	
	   			mm = STRING_Date.substr(2,2); // ab char 2, copy 2 stück
	
			   		// mm max 12 min 1
			   		if(parseInt(mm) > 12)
			   		{
			   			mm = '12';
			   		}
			   		if(parseInt(mm) < 1)
			   		{
			   			mm = '1';
			   		}
	
	   			yyyy = STRING_Date.substr(4,2); // ab char 4, copy 2 stück
	   			if(yyyy.length == 2)
	   			{
	   				yyyy = '20'+yyyy;
	   			}
	   		} 
	   		if(STRING_Date.length == 8)
	   		{
	   			// wir ham 01012008
	   			dd = STRING_Date.substr(0,2); // ab char 0, copy 2 stück
	
			   		// dd max 31 min 1
			   		if(parseInt(dd) > 31)
			   		{
			   			dd = '31';
			   		}
			   		if(parseInt(dd) < 1)
			   		{
			   			dd = '1';
			   		}
	
	   			mm = STRING_Date.substr(2,2); // ab char 2, copy 2 stück
	
			   		// mm max 12 min 1
			   		if(parseInt(mm) > 12)
			   		{
			   			mm = '12';
			   		}
			   		if(parseInt(mm) < 1)
			   		{
			   			mm = '1';
			   		}
	
	   			yyyy = STRING_Date.substr(4,4); // ab char 4, copy 4 stück
	   		}
	   		
	   		if(parseFloat(mm) > MAX_MM)
	   		{
	   			mm = MAX_MM.toString();
	   		}
	   		
	   		if(parseFloat(mm) < MIN_MM)
	   		{
	   			mm = MIN_MM.toString();
	   		}
	   		
	   		if(parseFloat(yyyy) > MAX_YYYY)
	   		{
	   			yyyy = MAX_YYYY.toString();
	   		}
	   		
	   		if(parseFloat(yyyy) < MIN_YYYY)
	   		{
	   			yyyy = MIN_YYYY.toString();
	   		}
	   				
			STRING_DateResult = dd+'.'+mm+'.'+yyyy;
			
			if(STRING_DateResult == '..')
			{
				// von .length hat nix gepasst. 
				STRING_DateResult = STRING_Date;
			}
			
			return STRING_DateResult;
			
		 	// var DATE_date:Date = string_to_date(STRING_Date,'DD.MM.YYYY');
		 }
	
		/** liefert ein aktuelle uhrzeit und datum zurück imf format DD.MM.YYY HH:MM:SS
		 * MODES['2 digit year'] = true -> 09 statt 2009
		 * DATE_SEPARATOR = '.' -> 20.12.2009
		 * TIME_SEPARATOR = ':' -> 12:33:09
		 * MODES['no time'] = true -> do not return time, just date.
		 **/
		public function aktuellesDatum_und_Uhrzeit(MODES:Object = null,TIME_SEPARATOR:String = ':',DATE_SEPARATOR:String = '.'):String
		{
			if(MODES == null)
			{
				MODES = {TwoDigitYear:false,time:true};
			}
			
			var STRING_Result:String = '';
			var datum:Date = new Date();
			
			var DD:String = datum.day.toString();
			var MM:String = (datum.month+1).toString(); // Flex assigns 0 to January, 1 to February, 2 to March, ...
			var YY:String = datum.fullYear.toString();

			if(MODES['TwoDigitYear'])
			{
				YY = YY.substring(2,4);
			}
			
			if(DD.length < 2) { DD = '0' + DD; }
			if(MM.length < 2) { MM = '0' + MM; }
			
			STRING_Result = DD+ DATE_SEPARATOR +MM+ DATE_SEPARATOR +YY;
			
			if(MODES['time'])
			{
				var HOUR:String = datum.hours.toString();
				var MIN:String = datum.minutes.toString();
				var SEC:String = datum.seconds.toString();
				
				if(HOUR.length < 2) { HOUR = '0' + HOUR; }
				if(MIN.length < 2) { MIN = '0' + MIN; }
				if(SEC.length < 2) { SEC = '0' + SEC; }
				
				STRING_Result = STRING_Result + ' ' +HOUR+ TIME_SEPARATOR +MIN+ TIME_SEPARATOR +SEC;
			} 
			
			return STRING_Result;
		}
		
		/** date 2 time **/
		public function date2time(DATE:Date,TIME_SEPARATOR:String = ':'):String
		{
			var result:String = "";

			var HOUR:String = DATE.hoursUTC.toString();
			var MIN:String = DATE.minutesUTC.toString();
			var SEC:String = DATE.secondsUTC.toString();
			
			if(HOUR.length < 2) { HOUR = '0' + HOUR; }
			if(MIN.length < 2) { MIN = '0' + MIN; }
			if(SEC.length < 2) { SEC = '0' + SEC; }
			
			result = result + ' ' +HOUR+ TIME_SEPARATOR +MIN+ TIME_SEPARATOR +SEC;
			
			return result;
		}
	
		/** konvertiert ein result event mit mysql datums angaben YYYY-MM-DD
		 * in ein array mit "normalen" datumsangaben DD.MM.YYYY
		 * INPUT:
		 * 		RESULTEVENT_result = das result event des http services
		 * 		ARRAY_FieldName = wie die properties des result ArrayCollection.source.objects heißt welche das datum beinhaltet.
		 * **/
		public function mysql_date_result_to_normal_date_format(RESULTEVENT_result:Event,ARRAY_FieldName:Array):Array
		{
			var ARRAY_Result:Array = new Array();
			var c_OBJECT_inst:c_OBJECT = new c_OBJECT();
			
			if(RESULTEVENT_result.type == 'result')
			{
				// 1. erstelle eine unabhängige kopie vom result (hoffentlich unabhängig)
				var ARRAY_HTTP_Result:Array = RESULTEVENT_result['result'].sqlxml.record.source.slice(); // result is vom typ ArrayCollection
				for(var counter:int = 0;!(counter == ARRAY_HTTP_Result.length);counter++)
				{
					ARRAY_Result[counter] = c_OBJECT_inst.copy(ARRAY_HTTP_Result[counter]);
					for(var counter2:int = 0;!(counter2 == ARRAY_FieldName.length);counter2++)
					{
						ARRAY_Result[counter][ARRAY_FieldName[counter2]] = mysql_date_to_date_string(ARRAY_HTTP_Result[counter][ARRAY_FieldName[counter2]]);
					}
				}
			}
			
			return ARRAY_Result;
		}
	
		/** konvertiert ein array mit mysql datums angaben YYYY-MM-DD
		 * in ein array mit "normalen" datumsangaben DD.MM.YYYY
		 * INPUT:
		 * 		ARRAY_HTTP_Result = das array mit den mysql datumsangaben
		 * 		ARRAY_FieldName = wie die properties des result ArrayCollection.source.objects heissen welche die datumsangaben beinhalten.
		 * **/
		public function CONVERT_mysql_date_array_to_normal_date_format(ARRAY_HTTP_Result:Array,ARRAY_FieldName:Array):Array
		{
			var ARRAY_Result:Array = new Array();
			var c_OBJECT_inst:c_OBJECT = new c_OBJECT();
			
			// 1. erstelle eine unabhängige kopie vom result (hoffentlich unabhängig)
			for(var counter:int = 0;!(counter == ARRAY_HTTP_Result.length);counter++)
			{
				ARRAY_Result[counter] = c_OBJECT_inst.copy(ARRAY_HTTP_Result[counter]);
				for(var counter2:int = 0;!(counter2 == ARRAY_FieldName.length);counter2++)
				{
					ARRAY_Result[counter][ARRAY_FieldName[counter2]] = mysql_date_to_date_string(ARRAY_HTTP_Result[counter][ARRAY_FieldName[counter2]]);
				}
			}
			return ARRAY_Result;
		}
		
		/** returns the recent date usually in this 'DD.MM.YYYY' format
		 * if one needs mysql-compatible format give aktuelles_Datum_as_String('sql'); **/ 
		public function aktuelles_Datum_as_String(FORMAT:String = 'DD.MM.YYYY'):String
		{
			var datum:Date = new Date();
			var STRING_Result:String = '';
			if(FORMAT == 'DD.MM.YYYY')
			{
				STRING_Result = date_to_string(datum,'DD.MM.YYYY'); // datum.dateUTC.toString()+'.'+(datum.monthUTC+1).toString()+'.'+datum.fullYear;
			}
			if((FORMAT == 'YYYY-MM-DD') || (FORMAT == 'sql'))
			{
				STRING_Result = date_to_string(datum,'YYYY-MM-DD'); // datum.dateUTC.toString()+'.'+(datum.monthUTC+1).toString()+'.'+datum.fullYear;
			}
			return STRING_Result;
		}
		public function aktuelles_Datum_as_Date():Date
		{
			var datum:Date = new Date();
			return datum;
		}
		
		/** aktuelles jahr als int **/ 
		public function aktuelles_Jahr_as_int():*
		{
			var datum:Date = new Date();
			return datum.fullYear;
		}

		/** aktuelles jahr als string **/ 
		public function aktuelles_Jahr_as_string():*
		{
			var datum:Date = new Date();
			return datum.fullYear;
			return datum.fullYear.toString();
		}

		/**
		 * 1day has 24hours, 1d == 24h
		 * 1hour has 60min,  1d == 24*60 == 1440 min
		 * 1min has 60seconds,  1d == 24*60*60 == 86400sec
		 * 1sec has 1000milliseconds,  1d == 24*60*60*1000 == 86400000 milliseconds
		 * **/
		public function Days2Milliseconds(Days:*):Number
		{
			var NUMBER_Days:Number;
			
			if(Days is String)
			{
				NUMBER_Days = parseFloat(Days);
			}
			if(Days is Number || Days is int)
			{
				NUMBER_Days = Days;
			}
			
			var milliSecPerDay:Number = 86400000;
		   
		   return NUMBER_Days * milliSecPerDay ;
		}
		
		/**
		 * 1day has 24hours, 1d == 24h
		 * 1hour has 60min,  1d == 24*60 == 1440 min
		 * 1min has 60seconds,  1d == 24*60*60 == 86400sec
		 * 1sec has 1000milliseconds,  1d == 24*60*60*1000 == 86400000 milliseconds
		 * 
		 * INPUT:
		 * DIGITS_AFTER_DOT -> if one wants 123.23 days (true) or 123 days (false).
		 * **/
		public function Milliseconds2Days(Milliseconds:*,DIGITS_AFTER_DOT:Boolean):Number
		{
			var c_formaters_inst:c_formaters = new c_formaters();
			var NUMBER_Days:Number;
			var NUMBER_Milliseconds:Number;
			
			if(Milliseconds is String)
			{
				NUMBER_Milliseconds = parseFloat(Milliseconds);
			}
			if(Milliseconds is Number)
			{
				NUMBER_Milliseconds = Milliseconds;
			}
			
			var milliSecPerDay:Number = 86400000;
		   
		   NUMBER_Days = NUMBER_Milliseconds / milliSecPerDay;
		   
		   if(DIGITS_AFTER_DOT == false)
		   {
		   		NUMBER_Days = c_formaters_inst.FormatFloat(NUMBER_Days);
		   		NUMBER_Days = c_formaters_inst.FormatFloat_to_precision(NUMBER_Days,0);
		   }
		   return NUMBER_Days;
		}
		
		/** give two dates and it will return the difference between them as object
		 * INPUT 
			 * DATE_a
			 * DATE_b
		 * OUTPUT
			 * OBJECT_Result['milliseconds'] 
			 * OBJECT_Result['seconds'] 
			 * OBJECT_Result['minutes'] 
			 * OBJECT_Result['hours'] 
			 * OBJECT_Result['days'] 
			 * OBJECT_Result['months'] -> this is not a exact value... the function assumes that 1 month lasts 30 days 
			 * OBJECT_Result['years'] 
			 * 
		 * */
		 public function date_difference(DATE_a:Date,DATE_b:Date):Object
		 {
		 	if(DATE_a != null && DATE_b != null)
		 	{
			 	var OBJECT_Result:Object = new Object();
			 	
			 	var DATE_Diff:Date = new Date(DATE_a.getTime() - DATE_b.getTime()); 
	
				var NUMBER_Diff:Number = DATE_Diff.getTime();
	
				 OBJECT_Result['milliseconds'] = NUMBER_Diff;  
				 OBJECT_Result['seconds'] = NUMBER_Diff / 1000;
				 OBJECT_Result['minutes'] = NUMBER_Diff / 1000 / 60;
				 OBJECT_Result['hours'] = NUMBER_Diff   / 1000 / 60 / 60;
				 OBJECT_Result['days']  = NUMBER_Diff   / 1000 / 60 / 60 / 24;
				 OBJECT_Result['months'] = NUMBER_Diff  / 1000 / 60 / 60 / 24 / 30;
				 OBJECT_Result['years']  = NUMBER_Diff  / 1000 / 60 / 60 / 24 / 365;
		 	} 
			 
			 return OBJECT_Result;
		 }
	
		 /**
		 * 1. reformatiert ein unvollständig eingegebenes datum mit dem aktuellen datum
		 * 2. checkt ob dd > 21 < 0, m > 12 < 0 etc. 
		 * ählich des Flex eingebauten DateValidators, nur dass dieser nicht zuverlässig validiert.
		 * user muss fähig sein Datum in folgenden formaten eingeben zu können
		 * 01.01.2008
		 * 01012008
		 * 0101
		 * 01
		 * STRING_Date.replace('.','');
		* @return An array of strings consisting of all substrings in 
		* the string that match the specified <code>pattern</code>.
	
	 	 **/
		
		 public function FUNC_reformat_Date(STRING_Date:String):String
		 {
		 	// 0. validieren ob ein gültiges format forliegt
		 	// 1. punkte entfernen, falls vorhanden
	       	
	       	var STRING_DateResult:String = '';
	       	
		 	if(STRING_Date == '')
		 	{
		 		STRING_DateResult = date_to_string(new Date());
		 		return STRING_DateResult; 
		 	}
	       	
	       	// replace funktion wo bis zu 3 punkte herausfiltert
	 		STRING_Date = STRING_Date.replace('.','');
	 		STRING_Date = STRING_Date.replace('.','');
	 		STRING_Date = STRING_Date.replace('.','');
	 		
	 		if(validateInt(STRING_Date) == false)
	 		{
	 			// no valid date
	 			// -> leave old date
	 			// STRING_DateResult = STRING_Date;
	 			// -> delete old date
	 			return '';
	 		}
	
			// Check if valid Int
			function validateInt(InputString:String):Boolean // Checkt ob es sich beim Input um ein gültiges Kontonummern-Format handelt d.h. eine ganz-zahlige Nummer ohne Vorzeichen. If input is a number -> true else -> false
			{
			    const RegExInt:RegExp = /^\d+$/g; // matches only int numbers
			    
			    if (RegExInt.test(InputString)) // test returns true if match, else false //// BE CAREFUL! .test proved to do true, false, true... validation errors.
			    {
			   		return true;
			    }
			    else
			    {
			   		return false;
			    }
			}
	 		
	 		var dd:String = '';
	 		var mm:String = '';
	 		var yyyy:String = '';
	     		
			var datum:Date = new Date(); // aktuelles datum
			
			STRING_Date
			
	   		// 2. schaun wie viel man hat
	   		if(STRING_Date.length == 1)
	   		{
	   			// wir ham 1
	   			dd = STRING_Date.substr(0,1); // ab char 0, copy 1 stück
	
			   		// dd max 31 min 1
			   		if(parseInt(dd) > 31)
			   		{
			   			dd = '31';
			   		}
			   		if(parseInt(dd) < 1)
			   		{
			   			dd = '1';
			   		}
	   			
	   			dd = '0'+dd;
	   			mm = (datum.month+1).toString();
	
			   		// mm max 12 min 1
			   		if(parseInt(mm) > 12)
			   		{
			   			mm = '12';
			   		}
			   		if(parseInt(mm) < 1)
			   		{
			   			mm = '1';
			   		}
	   			
	   			if(mm.length == 1)
	   			{
	   				mm = '0'+mm;
	   			}
				yyyy = datum.fullYear.toString();
	   		}
	   		
	   		if(STRING_Date.length == 2)
	   		{
	   			// wir ham 01
	   			dd = STRING_Date.substr(0,2); // ab char 0, copy 2 stück
	
			   		// dd max 31 min 1
			   		if(parseInt(dd) > 31)
			   		{
			   			dd = '31';
			   		}
			   		if(parseInt(dd) < 1)
			   		{
			   			dd = '1';
			   		}
	
	   			mm = (datum.month+1).toString();
	
			   		// mm max 12 min 1
			   		if(parseInt(mm) > 12)
			   		{
			   			mm = '12';
			   		}
			   		if(parseInt(mm) < 1)
			   		{
			   			mm = '1';
			   		}
	
	   			if(mm.length == 1)
	   			{
	   				mm = '0'+mm;
	   			}
				yyyy = datum.fullYear.toString();
	   		}
	   		if(STRING_Date.length == 3)
	   		{
	   			// wir ham 011
	   			dd = STRING_Date.substr(0,2); // ab char 0, copy 2 stück
	
			   		// dd max 31 min 1
			   		if(parseInt(dd) > 31)
			   		{
			   			dd = '31';
			   		}
			   		if(parseInt(dd) < 1)
			   		{
			   			dd = '1';
			   		}
	
	   			mm = STRING_Date.substr(2,1); // ab char 2, copy 2 stück
	
			   		// mm max 12 min 1
			   		if(parseInt(mm) > 12)
			   		{
			   			mm = '12';
			   		}
			   		if(parseInt(mm) < 1)
			   		{
			   			mm = '1';
			   		}
	
	   			if(mm.length == 1)
	   			{
	   				mm = '0'+mm;
	   			}
				yyyy = datum.fullYear.toString();
	   		} 
	   		if(STRING_Date.length == 4)
	   		{
	   			// wir ham 0101
	   			dd = STRING_Date.substr(0,2); // ab char 0, copy 2 stück
	
			   		// dd max 31 min 1
			   		if(parseInt(dd) > 31)
			   		{
			   			dd = '31';
			   		}
			   		if(parseInt(dd) < 1)
			   		{
			   			dd = '1';
			   		}
	
	   			mm = STRING_Date.substr(2,2); // ab char 2, copy 2 stück
	
			   		// mm max 12 min 1
			   		if(parseInt(mm) > 12)
			   		{
			   			mm = '12';
			   		}
			   		if(parseInt(mm) < 1)
			   		{
			   			mm = '1';
			   		}
	
	   			yyyy = datum.fullYear.toString();
	   		} 
	   		if(STRING_Date.length == 6)
	   		{
	   			// wir ham 010108
	   			dd = STRING_Date.substr(0,2); // ab char 0, copy 2 stück
	
			   		// dd max 31 min 1
			   		if(parseInt(dd) > 31)
			   		{
			   			dd = '31';
			   		}
			   		if(parseInt(dd) < 1)
			   		{
			   			dd = '1';
			   		}
	
	   			mm = STRING_Date.substr(2,2); // ab char 2, copy 2 stück
	
			   		// mm max 12 min 1
			   		if(parseInt(mm) > 12)
			   		{
			   			mm = '12';
			   		}
			   		if(parseInt(mm) < 1)
			   		{
			   			mm = '1';
			   		}
	
	   			yyyy = STRING_Date.substr(4,2); // ab char 4, copy 2 stück
	   			if(yyyy.length == 2)
	   			{
	   				yyyy = '20'+yyyy;
	   			}
	   		} 
	   		if(STRING_Date.length == 8)
	   		{
	   			// wir ham 01012008
	   			dd = STRING_Date.substr(0,2); // ab char 0, copy 2 stück
	
			   		// dd max 31 min 1
			   		if(parseInt(dd) > 31)
			   		{
			   			dd = '31';
			   		}
			   		if(parseInt(dd) < 1)
			   		{
			   			dd = '1';
			   		}
	
	   			mm = STRING_Date.substr(2,2); // ab char 2, copy 2 stück
	
			   		// mm max 12 min 1
			   		if(parseInt(mm) > 12)
			   		{
			   			mm = '12';
			   		}
			   		if(parseInt(mm) < 1)
			   		{
			   			mm = '1';
			   		}
	
	   			yyyy = STRING_Date.substr(4,4); // ab char 4, copy 4 stück
	   		} 
	   				
			STRING_DateResult = dd+'.'+mm+'.'+yyyy;
			
			if(STRING_DateResult == '..')
			{
				// von .length hat nix gepasst. 
				STRING_DateResult = STRING_Date;
			}
			
			return STRING_DateResult;
			
		 	var DATE_date:Date = c_DATE_inst.string_to_date(STRING_Date,'DD.MM.YYYY');
		 }
	
		/** liefert ein aktuelle uhrzeit und datum zurück imf format DD.MM.YYY HH:MM:SS
		 **/ 
		public function FUNC_aktuellesDatum_und_Uhrzeit():String
		{
			var STRING_Result:String = '';
			var datum:Date = new Date();
			STRING_Result = datum.day+'.'+(datum.month+1).toString()+'.'+datum.fullYear;
			// Flex assigns 0 to January, 1 to February, 2 to March, ...
			STRING_Result = STRING_Result + ' ' + datum.hours+':' + datum.minutes + ':' + datum.seconds;
			return STRING_Result;
		}
		
		/** konvertiert millisekunden angaben in einen date-string **/
		public function MILISEC_TO_DATE_STRING(MILISEC:Number):String
		{
			STRING_RESULT = '';
			var DATE:Date = new Date(MILISEC);
			STRING_RESULT = date_to_string(DATE);
			
			return STRING_RESULT;
		}
		
		/** converts seconds (as string or int or number) to milliseconds **/
		public function sec2ms(sec:Object):Number
		{
			var result:Number = 0;
			if(sec is String)
			{
				result = parseFloat(sec as String) * 1000;
			}
			else if((sec is int) || (sec is Number))
			{
				result = (sec as Number) * 1000;
			}
			
			return result;
		}
		
		/** converts minutes (as string or int or number) to milliseconds **/
		public function min2ms(min:Object):Number
		{
			var result:Number = 0;
			if(min is String)
			{
				result = parseFloat(min as String) * 1000 * 60;
			}
			else if((min is int) || (min is Number))
			{
				result = (min as Number) * 1000 * 60;
			}
			
			return result;
		}
		
		/** converts hours (as string or int or number) to milliseconds **/
		public function hour2ms(hour:Object):Number
		{
			var result:Number = 0;
			if(hour is String)
			{
				result = parseFloat(hour as String) * 1000 * 60 * 60;
			}
			else if((hour is int) || (hour is Number))
			{
				result = (hour as Number) * 1000 * 60 * 60;
			}
			
			return result;
		}
		
		/** DATE could be in this format 10/7/11 time in this 000028 -> 00h 00m 28sec **/
		public function string2TimeStamp(DATE_STRING:String,DATE_SEPARATOR:String,TIME:String):Number
		{
			var c_OBJECT_inst:c_OBJECT = new c_OBJECT();
			var TIMESTAMP:Number = 0;
			if(c_OBJECT_inst.not_empty(DATE_STRING))
			{
				var DATE:Date = string_to_date(DATE_STRING,"DD/MM/YYYY");
				
				var hh:String = TIME.substr(0,2);
				DATE.hours = parseFloat(hh);
				var min:String = TIME.substr(2,2);
				DATE.minutes = parseFloat(min);
				var sec:String = TIME.substr(4,2);
				DATE.seconds = parseFloat(sec);
				
				var TIMESTAMP:Number = DATE.getTime();
			}
			
			return TIMESTAMP;
		}
	}
}